﻿using MediatR;
using S.RBAC.Api.Application.Command.StaffCommand;
using S.RBAC.Infrastructure.Interface;

namespace S.RBAC.Api.Application.CommandHandlers.StaffHandler
{
    public class StaffDeleteCommandHandler : IRequestHandler<StaffDeleteCommand, int>
    {
        protected readonly IStaffRepository _staff;

        public StaffDeleteCommandHandler(IStaffRepository staff)
        {
            _staff = staff;
        }

        public async Task<int> Handle(StaffDeleteCommand request, CancellationToken cancellationToken)
        {
            var info = await _staff.GetStaffInfo(t => t.EmployeeID == request.EmployeeID);

            if (info!=null)
            {
                info.IsDel = true;

                _staff.UpdStaff(info);

                return 1;
            }

            return 0;
        }
    }
}
